package com.collectplus.express.parcel;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher.OnPhotoTapListener;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.collectplus.express.BaseActivity;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppHttp;
import com.collectplus.express.tools.BitmapUtil;

import droid.frame.view.ScaledImageView;

/**
 * 图片查看，传一个图片url过来
 * 
 * @author kaka
 * 
 */
public class LargePicturePreviewActivity extends BaseActivity {
	/**
	 * 方形ImageView
	 */
	private ScaledImageView mPicView;
	/**
	 * 原始图
	 */
	private PhotoView mOriginalView;
	/**
	 * pic url
	 */
	private String mPicUrl;
	/**
	 * type:0.查看正方包裹图片 ;<br>
	 * 1.是查看本地原图
	 */
	private int type;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		overridePendingTransition(R.anim.in_small2big_center, 0);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.large_picture_preview);
		mPicUrl = getIntent().getStringExtra("picUrl");
		type = getIntent().getIntExtra("type", 0);
		findView();
	}

	private void findView() {
		if (type == 0) {
			mPicView = (ScaledImageView) findViewById(R.id.order_iamge);
			findViewById(R.id.full_view).setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					finish();
				}
			});
			//
			AppHttp.getInstance().loadImage(mPicUrl, mPicView, true);
		} else {
			mOriginalView = (PhotoView) findViewById(R.id.original_image);
			mOriginalView.setOnPhotoTapListener(new OnPhotoTapListener() {
				@Override
				public void onPhotoTap(View arg0, float arg1, float arg2) {
					finish();
				}
			});
			findViewById(R.id.ariginal_view).setVisibility(View.VISIBLE);
			findViewById(R.id.reload_btn).setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Intent data = new Intent();
					data.putExtra("needreload", true);
					setResult(Activity.RESULT_OK, data);
					finish();
				}
			});
			Bitmap bitmap = BitmapUtil.getImageThumbnail(mPicUrl, 0, 0);
			mOriginalView.setImageBitmap(bitmap);
		}
	}

}
